package com.zhkj.crawl;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.digest.DigestUtil;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.tomcat.util.security.MD5Encoder;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.PublicKey;

public class d {
    public static void main(String[] args) throws IOException {
        String ck = "ACID=8026b8a0-1af0-4eff-81ee-e0e9fa4899df; TB_DC_Flap_Test=0; TB_Latency_Tracker_100=1; TB_Navigation_Preload_01=1; TB_SFOU-100=; TS013ed49a=01538efd7c9568fc07f2ee2863e1833bc7bd4fa185333f8202e1b4ef45e9cc07c997289661db7e6fd27355642888f5d43521f5778b; ak_bmsc=07D26543BA995FE4C7AF6C28830D5DDF~000000000000000000000000000000~YAAQnWgDFyqBbLZ9AQAA7LOOvQ5/xDnSTfm9foDIljvqLtVbMd94GAtv52Zqt9S3qUGiVdaJQjqmCh+y+Uu6ZZQtWBzhvciU5wXM4g8NqSiZ3OcLMfRKWxcbP9eblB3Dw8H5mJLQNBF28KE7Iku2fURozeKPUOpzvbJ4S8q0UCWKIAfpEP+K5WeDyvtP8YlsjO+rqZE8JNWVR9oW4eejNuK5L/CQrkZ1A6giNAmKPo8w+8otZJII63X1/9Q7IW4FvPa+kLHkzjuZ04Zgv7TbVs/nRtae6SbMJsdG5U7L3kha1s84t5Gtm09dAJdYb2asRvmK8Fd1vw994bRPO0Rk1eBh5AAS9hBxzxJn7h4sQp0T98MpsxYDxDufLLUanFQoiH6gy9P2mipWgg==; assortmentStoreId=3081; bm_mi=A1F38DA0DA690ED4E157AD396403B0AE~SWXWzxnvROGul8bQS7eEWqmb6oiYQGrH4TpDQpvAyRPlsVsw7YNztRywsS1BtnJpDUQwf5iAPE4NIwhSceqycMqLOCGTJdH3hvBWyFh8LbE3270OeAoCJHKtFRikuVXja2cc/qBl83oiO0bGNByKslj05T3bQ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iZ2lmdEFkZHJlc3MiOmZhbHNlfSwiYXNzb3J0bWVudCI6eyJub2RlSWQiOiIzMDgxIiwiZGlzcGxheU5hbWUiOiJTYWNyYW1lbnRvIFN1cGVyY2VudGVyIiwiYWNjZXNzUG9pbnRzIjpudWxsLCJpbnRlbnQiOiJQSUNLVVAiLCJzY2hlZHVsZUVuYWJsZWQiOmZhbHNlfSwiaW5zdG9yZSI6ZmFsc2UsInJlZnJlc2hBdCI6MTYzOTU4NDM4NTY1MSwidmFsaWRhdGVLZXkiOiJwcm9kOnYyOjgwMjZiOGEwLTFhZjAtNGVmZi04MWVlLWUwZTlmYTQ4OTlkZiJ9; locGuestData=eyJpbnRlbnQiOiJTSElQUElORyIsInN0b3JlSW50ZW50IjoiUElDS1VQIiwibWVyZ2VGbGFnIjpmYWxzZSwicGlja3VwIjp7Im5vZGVJZCI6IjMwODEiLCJ0aW1lc3RhbXAiOjE2Mzk1NjI3ODU2NDJ9LCJwb3N0YWxDb2RlIjp7InRpbWVzdGFtcCI6MTYzOTU2Mjc4NTY0MiwiYmFzZSI6Ijk1ODI5In0sInZhbGlkYXRlS2V5IjoicHJvZDp2Mjo4MDI2YjhhMC0xYWYwLTRlZmYtODFlZS1lMGU5ZmE0ODk5ZGYifQ%3D%3D; mobileweb=0; vtc=dAhgmmnmKJaf8flFoq4H54; xpa=aKAYi; xpm=1%2B1639562785%2BdAhgmmnmKJaf8flFoq4H54~%2B0; xptwg=1992672624:9C4DDA9CDD7A00:199736E:C8B28680:75D62C8E:4D1E30FD:; TS01b0be75=01538efd7cf45e3b7ac13e54bd99781b35d35198eae5874639d25f1edc070678635041110a3c95dccd6982f5de2811f338f3e204eb; _pxhd=hTOhXNfJ3TTJYzDWmHGpuPCSuAjbhFTmZBXbHf3CzYdQwLvOwQccZ7/QASRC42zhtMBYOO4S0hVqrj1a0RYcXA==:tlKWjMq5fibJne6xKhfeWZw6pZQOk/3iCPn4NwnOcvVgeuI82H/-1UF7A7GesvtEykUCqNZmqFKAwiAmPeHstXfBeGchGHxSReNega4gUiQ=";
        JSONObject json = new JSONObject();
        for (String s : ck.split("; ")) {
            String[] split = s.split("=", 2);
            if(split.length == 1){
                json.put(split[0], "");
            }else {
                json.put(split[0], split[1]);
            }
        }

//        System.out.println(json);
        String pubK = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmTV7B7xHF4hYpxJVBvFCeHvcqQ5ZqmyOc+riKyYIHOppCCTMJyZYy1NgKXbovhMxn3DYNohcRf8ko3P2T40NcYjIXG1Law7FJfyKSS36lHSttTYgq9fZKuj1rkeuPlkm9iejEbGjEczScjkMsYCcojQ9qyxjeJvwI6VKlkKgzWQIDAQAB";
        String priK = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKZNXsHvEcXiFinElUG8UJ4e9ypDlmqbI5z6uIrJggc6mkIJMwnJljLU2Apdui+EzGfcNg2iFxF/ySjc/ZPjQ1xiMhcbUtrDsUl/IpJLfqUdK21NiCr19kq6PWuR64+WSb2J6MRsaMRzNJyOQyxgJyiND2rLGN4m/AjpUqWQqDNZAgMBAAECgYAHV4hvbME5c0R3OO6TUF+0G2SIwSMgNxPYwljosldt6kW/1JgkPnobFGUqpVNVoGSbJpBcWbjwVNaUr0JNXSMuxrgc0zAjcnvKet4DBZqKgqs81GA7j7nkvr0HjVRW1mNVi2ZY3xlXh9HQzA3jBPjvdO00bmI7NToW4l9c9J0GYQJBANPREo+7pGlq7Mhv5zUVedggFEibtDxyXdmQ065Go0Ihfr/WXA+nouFBT4abggb6+fWw3dDIAumZ23oWziI4x28CQQDI/dflSEql2DVt+8MR6FVHXfkGIJzzjAYRW5Rglilu3N3tl1aoD5YGJusQvL8YLH95OlS9y+DzTNCMpV5Gnw23AkAHstun2bwaEMbWairPJR6umkvib7ZXVBjRJZBsDykz6B/BPTtPXlpvMX6Ad/p74ndfVLRbOEnSz8LIZzfKyqGFAkAxf7KH2QHpThH6gCJOarV12gLWK3n70OQ9qhwknVae4u4U8Ux6HzyHT1ZczN8TCQJrzJ3KEEfaI3TI7oEFS26JAkAkPIRtzgaIJteFZItBHCGHXnSWwPKrfRaFQ86OU7izNWw5GYJq+8++5ogx710bC1457rz+ogfMizinAPFsCOIl";
//        String digest = DigestUtil.md5Hex("cn1529436250njes|1636612739".getBytes(StandardCharsets.UTF_8));
//        System.out.println(digest);
        String digest = DigestUtil.md5Hex("cn1529436250njes|1640921174".getBytes(StandardCharsets.UTF_8));
        byte[] publicKeyBytes = Base64.decodeBase64(pubK.getBytes(StandardCharsets.UTF_8));
        byte[] privateKeyBytes = Base64.decodeBase64(priK.getBytes(StandardCharsets.UTF_8));
        RSA rsa = new RSA(privateKeyBytes, publicKeyBytes);
        byte[] encrypt = rsa.encrypt(digest, KeyType.PublicKey);
        String utf8 = new String(Base64.encodeBase64(encrypt));

        System.out.println(digest);
        System.out.println(utf8);
        utf8 = "gkRzF4BO/GdxmRd8YG0YS5EdSRtQA67VkspbSEmJUODfnfo+s1b8Es9YvZe1Zd+1l1xRNovWExjIa/s6JRVDF0K5KaGfZCgMbn0qt3E6CwhUQUomztb62kg4PtqlP8FFa3DNciSHGZ/+zkn0crFrLduw+vc2jjyj9TFRKHXzUV4=";
        byte[] decrypt = rsa.decrypt(Base64.decodeBase64(utf8.getBytes(StandardCharsets.UTF_8)), KeyType.PrivateKey);
        System.out.println(new String(decrypt));
    }
}
